package com.kun.config;

import com.kun.bean.Color;
import com.kun.bean.ColorFactoryBean;
import com.kun.bean.Person;
import com.kun.bean.Red;
import com.kun.condition.LinuxCondition;
import com.kun.condition.MyImportBeanDefinitionRegistrar;
import com.kun.condition.MyImportSelector;
import com.kun.condition.WindowsCondition;
import org.springframework.context.annotation.*;

/**
 * @author fangkun
 * @create 2022-04-25-14:18
 */
@Conditional(WindowsCondition.class)
@Configuration
@Import({Color.class, Red.class, MyImportSelector.class, MyImportBeanDefinitionRegistrar.class})
public class MainConfig2 {

    // 通过@Scope注解来指定该bean的作用范围，也可以说成是调整作用域
    @Lazy
    @Scope("prototype")
    @Bean("person")
    public Person person() {
        System.out.println("给容器中添加咱们这个Person对象...");
        return new Person("娄德华", 25);
    }


    @Bean("bill")
    public Person person01() {
        return new Person("Bill Gates", 62);
    }

    @Conditional(LinuxCondition.class)
    @Bean("linus")
    public Person person02() {
        return new Person("linus", 48);
    }

    @Bean
    public ColorFactoryBean colorFactoryBean() {
        return new ColorFactoryBean();
    }
}

